package com.runa.monitor.platinterface.netservice.equipment.ex;

import java.util.concurrent.PriorityBlockingQueue;

public class ExQueueManager {

    private static ExQueueManager manager;

    private PriorityBlockingQueue<Object> queue;

    private ExQueueManager(){
        queue = new PriorityBlockingQueue();
    }

    public static ExQueueManager getInstance(){
        if (null==manager){
            synchronized (ExQueueManager.class){
                if (null==manager){
                    manager = new ExQueueManager();
                }
            }
        }
        return manager ;
    }


    /**
     * 添加
     */
    public <T extends Comparable> void add(T t){
        queue.add(t);
    }


    /**
     * 取出
     */
    public <T extends Comparable> T take(){
        try {
            if (!queue.isEmpty()){
                return (T) queue.take();
            }
        } catch (InterruptedException e) {
            
        }
        return null ;
    }


    public boolean isEmpty(){
        return queue.isEmpty();
    }

}
